/**
 * Application���ܣ�
 *	 ��ʼ��Ӧ�ó����������ĸ�����ص���
 * 	 ��ͼ���
 *   �������Ӧ�ó�������岼��
 * ִ�й�̣�
 *   ��ʼ������ࣨcontrollers��-> ִ��launch����->��Ⱦ
 *     
 */

Ext.application({
    requires: ['Ext.container.Viewport'],
    name: 'Risk',
    appFolder: 'app',
    controllers:[
        
     ],
    //应用程序入口 加载主试图
    launch: function() {
	    var imgPanel = null ;
	    var jspPanel = null ;
	    var swfPanel = null ;
    
    	//console.log('launch is invoking !');
   		Ext.create('Ext.container.Viewport', {
		    layout: 'border',
		    autoScroll :true,
//		    renderTo:Ext.getBody(),
		    items: [{
		    	itemId:'north',
		        region: 'north',
		        html: '<h1 class="x-panel-header">Page Title</h1>',
		        xtype: 'panel',
		        height:80,
		        margins: '0 0 5 0'
		    }, {
		    	//导航
		    	itemId:'west',
		    	title: '导航栏',
		        region: 'west',
		        xtype: 'treepanel',
		        rootVisible:false,
		        collapsible: false,
		        width: 160,
		        store:new Ext.data.TreeStore({
		        	nodeParam:'id',
					proxy:{
						type:'ajax',
						url:'module/modules.do' ,
						reader:{
							type:'json',
							root:'root'
						}
					},
					root:{expanded:true}
				}),
        		listeners:{
        			"itemclick":function(tg, record, item, index, e, eOpts ){
	        			var maintab = Ext.getCmp("maintab") ;
	        			
	        			if(jspPanel != null && jspPanel.ownerCt == maintab){
        					maintab.remove(jspPanel , false);
        				}
	        			
	        			var myhref = record.raw.myhref ;
	        			var contenttype = record.raw.contenttype ;
	        			var innerpanel = null ;
	        			
	        			if(contenttype == "jsp"){
//	        				if(jspPanel == null){
	        					jspPanel = new Ext.panel.Panel({
	        						closable:true,
	        						closeAction:'hide',
	        						loader:{
	        							scripts:true
	        						}
	        					});
//		    				}
	        				
	        				innerpanel = jspPanel ;
//	        				var loader = innerpanel.getLoader() ;
//	    					loader.url = myhref ;
//	    					loader.load();
	        				innerpanel.html = "<iframe src='"+myhref+"' width='100%' height='100%'></iframe>" ;
	        				
	        			}else if(contenttype == "swf"){
	        				if(swfPanel == null){
	        					swfPanel = new Ext.FlashComponent({
	        						closable:true,
	        						closeAction:'hide',
	        						expressInstall :true,
	        		        		flashParams:{
	        		        			wmode:'transparent'
	        		        		}
	        					});
	        				}
	        				innerpanel = swfPanel ;
	        				innerpanel.url = myhref ;
	        			}else{
	        				if(imgPanel == null){
		    					imgPanel = new Ext.Img({
		    						closable:true,
		    						closeAction:'hide'
		    					});
		    				}
	        				innerpanel = imgPanel ;
	        				innerpanel.setSrc( myhref );
	        			}
//	        			if(innerpanel.ownerCt != maintab){
//	        				if(jspPanel != null && jspPanel.ownerCt == maintab){
//	        					maintab.remove(jspPanel , false);
//	        				}else if(imgPanel != null && imgPanel.ownerCt == maintab){
//	        					maintab.remove(imgPanel , false);
//	        				}else if(swfPanel != null && swfPanel.ownerCt == maintab){
//	        					maintab.remove(swfPanel , false);
//	        				}
	    					maintab.add(innerpanel);
//	    				}
//	        			maintab.setActiveTab(innerpanel);
        			}
        		}
		    }, {
		    	xtype: 'tabpanel',
		    	id:'maintab',
		    	itemId:"center",
		        region: 'center',
		        autoDestroy:false,
		        items: []
		    }]
		});
    }
});